﻿#region License
// Copyright (c) 2009 Shengmin Zhang
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.Web.Caching;

using Apprender.Web.Caching;

namespace Apprender.Web
{
    [AttributeUsage(AttributeTargets.Method,AllowMultiple=false) ]
    [Serializable]
    public sealed class DataServiceMethodAttribute : Attribute,ICacheSetting
    {       

        public DataServiceMethodAttribute() 
        {            
            this._cacheDuration = 0;            
            this._useSlidingCache = false;           
            this._responseContentType = HttpResponseContentType.Json;
            this._cacheMode = CacheMode.Memory;
            this._cacheItemPriority = CacheItemPriority.Normal;
            this._cacheDir = string.Empty;//"~/__apprenderweboutputcache";
            this._enableCompression = false;
        }

        private bool _enableCompression;
        public bool EnableCompression
        {
            get { return this._enableCompression; }
            set { this._enableCompression = value; }
        }

        private string _cacheDir;
        public string CacheDirectory
        {
            get { return this._cacheDir; }
            set { this._cacheDir = value; }
        }


        private HttpResponseContentType _responseContentType;
        /// <summary>
        /// Specify response content type, default is JSON
        /// </summary>
        public HttpResponseContentType ResponseContentType
        {
            get { return this._responseContentType; }
            set { this._responseContentType = value; }
        }

        private bool _useSlidingCache;
        /// <summary>
        /// Specify whether or not to use sliding cache 
        /// Default is false        
        /// </summary>
        public bool UseSlidingCache
        {
            get { return this._useSlidingCache; }
            set { this._useSlidingCache = value; }
        }        
        
        private double _cacheDuration;
        /// <summary>
        /// Specify cache duration in seconds, 
        /// Default is 30 seconds
        /// </summary>
        public double CacheDuration
        {
            get { return this._cacheDuration; }
            set { this._cacheDuration = value; }
        }

        //private bool _enableCaching;
        /// <summary>
        /// Specify whether or not to cache result, default is false
        /// </summary>
        [Obsolete("Please set CacheDuration greater than 0 in order to enable caching",true)]
        public bool EnableCaching
        {
            get { return false; }
            //set { this._enableCaching = value; }
        }

        private CacheMode _cacheMode;
        public CacheMode CacheMode
        {
            get { return this._cacheMode; }
            set { this._cacheMode = value; }
        }

        private string[] _cacheKeyElements;        
        public string[] CacheKeyElements
        {
            get { return this._cacheKeyElements; }
            set { this._cacheKeyElements = value; }
        }

        private CacheItemPriority _cacheItemPriority;
        /// <summary>
        /// Default is Normal
        /// </summary>
        public CacheItemPriority CacheItemPriority
        {
            get { return this._cacheItemPriority; }
            set { this._cacheItemPriority = value; }
        }


    }
}
